package pl.grabar.clinic.core;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.jersey.spi.inject.Inject;

import pl.grabar.clinic.core.dao.Dao;
import pl.grabar.clinic.core.dao.db.VisitDataBaseDao;
import pl.grabar.clinic.core.domain.person.Patient;
import pl.grabar.clinic.core.domain.visit.Visit;

@Component
@Path("/visit")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class CrudServiceTest  {
	
	@Autowired
	private Dao<Patient> patientDao;
	
	@Autowired
	private VisitDataBaseDao visitDao;

	@GET
	@Path("/patient/get/{id}")
	@Produces(MediaType.APPLICATION_JSON)
	public Patient get(@PathParam("id") String id){
		try {
			return patientDao.findById(id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	@GET
	@Path("/{param}")
	public Response getMsg(@PathParam("param") String msg) {
 
		System.out.println("dupa"+msg);
		String output = "Jersey say : " + msg;
 
		return Response.status(200).entity(output).build();
 
	}

//	public void setPatientDao(Dao<Patient> patientDao) {
//		this.patientDao = patientDao;
//	}

	@POST
	@Path("/getVisits2")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Visit> getPatinetList2(){
		return visitDao.getVisitToArchive();
	}
	
	@GET
	@Path("/getVisits")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Visit> getPatinetList(){
		return visitDao.getVisitToArchive();
	}

	

	/*AKCESORY*/

	public void setVisitDao(VisitDataBaseDao visitDao) {
		this.visitDao = visitDao;
	}

	public void setPatientDao(Dao<Patient> patientDao) {
		this.patientDao = patientDao;
	}
	
}
